<div class="contract-infos">
	<div class="text-danger selected-info" style="padding-bottom: 10px;">请选择需要关联的投标信息</div>

	<table class="to-link-contract table-condensed" data-page="${page!1}" data-page-size="${pageSize!15}" data-count="${count!0}">
		<tr>
			<th class="text-center" width="24"></th>
			<th class="text-center" width="180">合同编号</th>
			<th class="text-center">合同名称</th>
		</tr>
		<#if data?? && (data?size &gt; 0)> <#list data as d>
		<tr class="contract-row" style="cursor: pointer;">
			<td class="for-radio" style="vertical-align: middle;"><input type="checkbox" name="contract-id" value="${d.id}"></td>
			<td class="text-center no">${d.no}</td>
			<td class="name">${d.name}</td>
		</tr>
		</#list> <#else>
		<tr>
			<td class="text-danger" colspan="4">暂无可关联的收款合同信息！</td>
		</tr>
		</#if>
	</table>
</div>

<script type="text/javascript">
	require([ 'suredyList' ], function(List) {
		List('.to-link-contract', {
			header : false,
			search : false,
			paginate : function(page, pageSize, key) {
				$.get('${request.contextPath}/contract/link-contract', {
					page : page,
					pageSize : pageSize
				}, function(html, textStatus, jqXHR) {
					if (html) {
						$('div.contract-infos').parent().html(html);
					}
				}, 'html');
			}
		});

		$('table.to-link-contract tr.contract-row > td').on('click', function(event) {
			var $this = $(this);

			if ($this.hasClass('for-radio'))
				return true;

			$('[name="contract-id"]', $(this).parent()).click().trigger('change');

			return true;
		});

		$('[name="contract-id"]').on('change', function() {
			var $this = $(this);

			var info = $('div.selected-info');
			var checked = $('[name="contract-id"]:checked');

			if (checked.length == 0) {
				info.html('请选择需要关联的投标信息');
			} else {
				var html = '&lt;已选择&gt;：';
				$('[name="contract-id"]:checked').each(function(i, v) {
					var $me = $(v);
					var tr = $me.parent().parent();
					html += '【' + tr.find('>td.no').text() + '】、';
				});
				info.html(html.replace(/、$/, ''));
			}
		});
	});
</script>
